package com.cy.utils;

import com.cy.anno.Autowired;
import com.cy.anno.Component;

import java.sql.SQLException;

@Component
public class TransactionManager {

    @Autowired
    private ConnectionUtils connectionUtils;

    public void beginTransaction() throws SQLException {
        System.out.println("开始事务");
        connectionUtils.getConnection().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        System.out.println("提交事务");
        connectionUtils.getConnection().commit();
    }

    public void rollback() throws SQLException {
        System.out.println("回滚事务");
        connectionUtils.getConnection().rollback();
    }
}
